//ssc install estout
//ssc install rwolf2

global replica_dir="<add path to your working directory>"

global data_dir=	"$replica_dir/data"
global output_dir=	"$replica_dir/output"

use "$data_dir/panel_simce4b6_sned_studlvl.dta", clear

/*----------------------------------------------------------------------------*/

**# Table A7:  
 
/*----------------------------------------------------------------------------*/


global indepvars "sch_municip_pre rural_rbd sch_stno_pre i.tipo_est_num i.mom_edu_pre i.dad_edu_pre i.pad_inc_pre i.sch_gse_pre i.hg i.sned_yr"  
global depvars "mate lect"  

la var mate_post "Grade 6 Math Score"
la var lect_post "Grade 6 Reading Score"

la var treat25 "Full vs. Partial Bonus"
la var treat10 "Partial vs. No Bonus"
 

keep if stay_sch==1


	
 
/*------------------------------------------------------------------------------ 
	
	All
*/

eststo clear


local sample="all"

foreach yvar of global depvars{
	
local label_`yvar': variable label `yvar'_post

eststo: reg `yvar'_post `yvar'_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if abs(st_ind25) <= 1.5 , vce(cluster rbd)
eststo: reg `yvar'_post `yvar'_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if abs(st_ind10) <= 1.5, vce(cluster rbd)

}				
				
 

/*------------------------------------------------------------------------------

	PV
	
*/				
	
local sample="pv"
	
foreach yvar of global depvars{
	
local label_`yvar': variable label `yvar'_post

eststo: reg `yvar'_post `yvar'_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if sch_municip_pre==0 & abs(st_ind25) <= 1.5 , vce(cluster rbd)
eststo: reg `yvar'_post `yvar'_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if sch_municip_pre==0 & abs(st_ind10) <= 1.5, vce(cluster rbd)

}				



/*------------------------------------------------------------------------------

	MV
	
*/		

local sample="mv"
 
foreach yvar of global depvars{
	
local label_`yvar': variable label `yvar'_post

eststo: reg `yvar'_post `yvar'_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if sch_municip_pre==1 & abs(st_ind25) <= 1.5, vce(cluster rbd)
eststo: reg `yvar'_post `yvar'_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if sch_municip_pre==1 & abs(st_ind10) <= 1.5, vce(cluster rbd)

}				


/*----------------------------------------------------------------------------
	
	Multiple hypothesis testing
*/


rwolf2 ///	
	(reg mate_post mate_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if 					abs(st_ind25) <= 1.5 , vce(cluster rbd)) ///
	(reg mate_post mate_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if 					abs(st_ind10) <= 1.5 , vce(cluster rbd)) /// 
	(reg lect_post lect_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if 					abs(st_ind25) <= 1.5 , vce(cluster rbd)) ///
	(reg lect_post lect_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if 					abs(st_ind10) <= 1.5 , vce(cluster rbd)) /// 
	(reg mate_post mate_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if sch_municip_pre==0 & abs(st_ind25) <= 1.5, vce(cluster rbd)) ///
	(reg mate_post mate_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if sch_municip_pre==0 & abs(st_ind10) <= 1.5, vce(cluster rbd)) /// 
	(reg lect_post lect_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if sch_municip_pre==0 & abs(st_ind25) <= 1.5, vce(cluster rbd)) ///
	(reg lect_post lect_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if sch_municip_pre==0 & abs(st_ind10) <= 1.5, vce(cluster rbd)) /// 
	(reg mate_post mate_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if sch_municip_pre==1 & abs(st_ind25) <= 1.5, vce(cluster rbd)) ///
	(reg mate_post mate_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if sch_municip_pre==1 & abs(st_ind10) <= 1.5, vce(cluster rbd)) /// 
	(reg lect_post lect_pre treat25 st_ind25 st_ind25_sq inter25 inter25_sq  ${indepvars} if sch_municip_pre==1 & abs(st_ind25) <= 1.5, vce(cluster rbd)) ///
	(reg lect_post lect_pre treat10 st_ind10 st_ind10_sq inter10 inter10_sq  ${indepvars} if sch_municip_pre==1 & abs(st_ind10) <= 1.5, vce(cluster rbd)) /// 
	, ///
	indepvars(	treat25, treat10,  /// 
				treat25, treat10,  ///
				treat25, treat10,  ///
				treat25, treat10,  ///
				treat25, treat10,  ///
				treat25, treat10  /// 
								) seed(12011303)  cluster(rbd) strata(sned_yr) idcluster(newclusterid) usevalid reps(500) //holm
		
matrix RW=e(RW)		

matrix list RW

foreach v of numlist 1(1)12{ // each variable is a row in RW

scalar rw_pv=RW[`v',3]
scalar h_pv =RW[`v',4]
estadd scalar rw_pv : est`v'
estadd scalar h_pv :  est`v' 

}

*   

local sample="all"
esttab est1 est2 est3 est4  using "$output_dir/post_6b4_inc_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2   rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"'   `"Romano-Wolf p-value"' ))

local sample="pv"
esttab est5 est6 est7 est8 using "$output_dir/post_6b4_inc_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2   rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"'   `"Romano-Wolf p-value"' ))

local sample="mv"
esttab est9 est10 est11 est12 using "$output_dir/post_6b4_inc_`sample'.tex", tex nolines fragment label replace  collabels(none) nomtitles nonumbers star(* 0.10 ** 0.05 *** 0.01) ///
cells(b(star fmt(3)) se(par(( )) fmt(3)) ) ///
keep(treat25 treat10) ///
stats(N r2   rw_pv , fmt(0 3 3 3)  ///
labels(`"Observations"' `"R-squared"'   `"Romano-Wolf p-value"' ))
				


eststo clear



*----------------------------------   end



 
